﻿using System.Collections.Concurrent;
using LiJ.Orm.Core.Model;

namespace LiJ.Orm.Core.Util
{
    /// <summary>
    /// ORM框架缓存工具
    /// </summary>
    internal static class OrmCacheUtil
    {
        private static readonly ConcurrentDictionary<string, OrmOperateInfo> cacheList;

        static OrmCacheUtil()
        {
            cacheList = new ConcurrentDictionary<string, OrmOperateInfo>();
        }

        /// <summary>
        /// 获取缓存信息
        /// </summary>
        /// <param name="key">key值</param>
        /// <returns></returns>
        public static OrmOperateInfo GetCacheInfo(string key)
        {
            return cacheList.TryGetValue(key, out OrmOperateInfo info) ? info : null;
        }

        /// <summary>
        /// 添加缓存信息
        /// </summary>
        /// <param name="key">key值</param>
        /// <param name="info">orm操作信息实体类</param>
        public static void AddCacheInfo(string key, OrmOperateInfo info)
        {
            cacheList.TryAdd(key, info);
        }
    }
}